<script setup>
import { formProps } from 'element-plus';

// let props = defineProps({
//   control: Object,
//   formProps: Object,
//   enData: Object
// })
const control = defineModel("control")
defineProps({
  enData: Object,
  formProps: Object,
})
function requiredChange(value) {
  control.value.rules[0].required = value;
}

function requiredMessageChange(value) {
  control.value.rules[0].message = value;
}

function patternChange(value) {
  if (value) {
    control.value.rules[1].pattern = eval(value);
  }
}

function patternMessageChange(value) {
  control.value.rules[1].message = value;
}

function changeFormat() {
  control.value.props.minValue = ''//最小值
  control.value.props.maxValue = ''//最大值
  control.value.props.minLength = ''//最小长度
  control.value.props.maxLength = ''//最大长度
}
</script>

<template>
  <el-form label-width="90px">
    <!--        <el-form-item label="Id">-->
    <!--            <el-input v-model="control.id" placeholder=""></el-input>-->
    <!--        </el-form-item>-->
    <el-form-item label="中文名称">
      <el-input v-model="control.props.label" placeholder="请输入中文名称" :disabled="control.props.disabled"></el-input>
    </el-form-item>
    <el-form-item label="英文名称">
      <el-select v-if="enData?.options?.length" v-model="control.props.enName" placeholder="请选择英文名称"
        style="width: 100%">
        <el-option v-for="(item, index) in enData.options" :key="index" :label="item[enData.label]"
          :value="item[enData.value]" />
      </el-select>
      <el-input v-else v-model="control.props.enName" placeholder="请输入英文名称"></el-input>
    </el-form-item>
    <el-form-item label="填写提示">
      <el-input v-model="control.props.placeholder" placeholder="请输入填写提示"></el-input>
    </el-form-item>
    <el-form-item label="类型">
      <el-select v-model="control.props.inputType" placeholder="请选择类型" style="width: 100%">
        <el-option label="文本" value="text" />
        <el-option label="密码" value="password" />
      </el-select>
    </el-form-item>
    <el-form-item label="格式验证">
      <el-select v-model="control.props.formatVerify" placeholder="请选择格式" style="width: 100%" @change="changeFormat">
        <el-option label="文本" value="text" />
        <el-option label="中文" value="zh" />
        <el-option label="英文" value="en" />
        <el-option label="整数" value="integer" />
        <el-option label="小数" value="decimal" />
        <el-option label="数字" value="number" />
        <el-option label="手机" value="mobile" />
        <el-option label="固话" value="tel" />
        <el-option label="手机或固话" value="phone" />
        <el-option label="身份证号" value="idCard" />
        <el-option label="邮箱" value="email" />
        <el-option label="网址" value="website" />
      </el-select>
    </el-form-item>
    <template v-if="['integer', 'decimal'].includes(control.props.formatVerify)">
      <el-form-item label="最小值">
        <el-input-number v-model="control.props.minValue" :min="1" placeholder="请输入最小值" style="width: 100%" />
      </el-form-item>
      <el-form-item label="最大值">
        <el-input-number v-model="control.props.maxValue" :min="1" placeholder="请输入最大值" style="width: 100%" />
      </el-form-item>
    </template>
    <template v-if="['text', 'zh', 'en', 'email', 'website'].includes(control.props.formatVerify)">
      <el-form-item label="最小长度">
        <el-input-number v-model="control.props.minLength" :min="1" placeholder="请输入最小长度" style="width: 100%" />
      </el-form-item>
      <el-form-item label="最大长度">
        <el-input-number v-model="control.props.maxLength" :min="1" placeholder="请输入最大长度" style="width: 100%" />
      </el-form-item>
    </template>
    <el-form-item label="默认值">
      <el-input v-model="control.props.defaultValue" placeholder="请输入默认值"></el-input>
    </el-form-item>
    <el-form-item label="描述信息">
      <el-input type="textarea" rows="5" v-model="control.props.remark" placeholder="请输入描述信息"></el-input>
    </el-form-item>

    <!--        <el-form-item label="宽度">-->
    <!--            <el-slider-->
    <!--                class="w-11/12"-->
    <!--                :min="0"-->
    <!--                :max="formProps.cols"-->
    <!--                show-stops-->
    <!--                v-model="control.props.width"-->
    <!--            ></el-slider>-->
    <!--        </el-form-item>-->


    <!--        <el-form-item label="显示密码" v-if="control.props.type == 'password'">-->
    <!--            <el-switch v-model="control.props.showPassword"></el-switch>-->
    <!--        </el-form-item>-->

    <el-form-item label="字数统计" v-if="control.props.type == 'text'">
      <el-switch v-model="control.props.showWordLimit"></el-switch>
    </el-form-item>
    <!--        <el-form-item label="最大长度" v-if="control.props.showWordLimit">-->
    <!--            <el-input-number v-model="control.props.maxlength" :min="1" />-->
    <!--        </el-form-item>-->

    <!--        <el-form-item label="显示标题">-->
    <!--            <el-switch v-model="control.props.showLabel"></el-switch>-->
    <!--        </el-form-item>-->
    <!--        <el-form-item label="标题宽度">-->
    <!--            <el-input-number v-model="control.props.labelWidth" :min="0" />-->
    <!--        </el-form-item>-->
    <!--        <el-form-item label="正则验证">-->
    <!--            <el-input @change="patternChange" v-model="control.props.pattern"></el-input>-->
    <!--        </el-form-item>-->
    <!--        <el-form-item label="正则提示" v-if="control.props.pattern">-->
    <!--            <el-input @change="patternMessageChange" v-model="control.props.patternMessage"></el-input>-->
    <!--        </el-form-item>-->

    <!--        <el-form-item label="是否可清空">-->
    <!--            <el-switch v-model="control.props.clearable"></el-switch>-->
    <!--        </el-form-item>-->
    <el-form-item label="是否可搜索">
      <el-switch v-model="control.props.isSearch"></el-switch>
    </el-form-item>
    <el-form-item label="是否禁用">
      <el-switch v-model="control.props.disabled"></el-switch>
    </el-form-item>
    <el-form-item label="加密显示">
      <el-switch v-model="control.props.encryption"></el-switch>
    </el-form-item>
    <el-form-item label="是否必填">
      <el-switch @change="requiredChange" v-model="control.props.required"></el-switch>
    </el-form-item>
    <el-form-item label="必填提示" v-if="control.props.required">
      <el-input @change="requiredMessageChange" v-model="control.props.requiredMessage"></el-input>
    </el-form-item>
    <!--            <el-form-item label="是否只读">-->
    <!--                <el-switch v-model="control.props.readonly"></el-switch>-->
    <!--            </el-form-item>-->
  </el-form>
</template>
